<?php


namespace app\index\controller;


use app\common\Tools;
use think\Controller;

/**
 * 公共控制器
 * Class Common
 * @package app\index\controller
 */
class Common extends Controller
{
    /**
     * 上傳文件
     */
    public function UploadFile()
    {
        $Result = Tools::mb_UploadQiNiu('File');
        if($Result['result']){
            mb_OutMessage(ErrCode_Normal,'',array('src'=>$Result['key']));
        } else {
            mb_OutMessage(ErrCode_Toast,'上传文件错误');
        }
    }
    /**
     * 上传图片
     */
    public function UploadImage()
    {
        $AllowExts = ['jpg','png','gif','jpeg','bmp'];
        $Temp = explode('.', $_FILES['Image']['name']);
        $Extend = end($Temp);
        if (in_array($Extend, $AllowExts)){
            //合法文件
            $Result = Tools::mb_UploadQiNiu('Image');
            if($Result['result']){
                mb_OutMessage(ErrCode_Normal,'',array('src'=>$Result['key']));
            } else {
                mb_OutMessage(ErrCode_Toast,'上传文件错误');
            }
        } else {
            //非法文件
            mb_OutMessage(ErrCode_Toast,'非法文件');
        }
    }
    /**
     * 上传音频
     */
    public function UploadVoice()
    {
        $AllowExts = ['mp3','wma'];
        $Temp = explode('.', $_FILES['Voice']['name']);
        $Extend = end($Temp);
        if (in_array($Extend, $AllowExts)){
            //合法文件
            $Result = Tools::mb_UploadQiNiu('Voice');
            if($Result['result']){
                mb_OutMessage(ErrCode_Normal,'',array('src'=>$Result['key']));
            } else {
                mb_OutMessage(ErrCode_Toast,'上传文件错误');
            }
        } else {
            //非法文件
            mb_OutMessage(ErrCode_Toast,'非法文件');
        }
    }
}